package com.mooc.meetingfilm.utils.common.vo;

import com.mooc.meetingfilm.utils.exception.BaseServiceException;
import lombok.Data;

@Data
public class BaseResponseVO<T> {
    private Integer code;
    private String msg;
    private T data;

    private BaseResponseVO() {

    }

    private BaseResponseVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <M> BaseResponseVO<M> success(M data) {
        BaseResponseVO<M> baseResponseVO = new BaseResponseVO<>(200, "成功", data);
        return baseResponseVO;
    }

    public static <M> BaseResponseVO<M> success() {
        return success(null);
    }

    public static <M> BaseResponseVO<M> fail() {
        BaseResponseVO<M> baseResponseVO = new BaseResponseVO<>(500, "失败", null);
        return baseResponseVO;
    }

    public static BaseResponseVO returnBaseServiceException(BaseServiceException e){
        BaseResponseVO baseResponseVO = new BaseResponseVO(e.getCode(), e.getMessage(), null);
        return baseResponseVO;
    }
}
